#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>

bool is_prime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i += 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}

int find_closest_prime(int n) {
    if (is_prime(n)) return n;
    
    int lower = n - 1;
    int upper = n + 1;
    
    while (true) {
        if (is_prime(lower)) return lower;
        if (is_prime(upper)) return upper;
        lower--;
        upper++;
    }
}

int main() {
    std::unordered_map<std::string, int> digits = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3},
        {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7},
        {"eight", 8}, {"nine", 9}
    };
    
    std::string word;
    int number = 0;
    
    for (int i = 0; i < 3; ++i) {
        std::cin >> word;
        
        if (digits.find(word) == digits.end()) {
            std::cout << "Wrong input";
            return 0;
        }
        
        number = number * 10 + digits[word];
    }

    if (number < 100 || number > 999) {
        std::cout << "Wrong input";
    } else {
        std::cout << find_closest_prime(number);
    }
    
    return 0;
}